package org.admanager.soapattern.plugin.diagram.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.admanager.soapattern.plugin.diagram.edit.parts.PComponent2EditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PComponentEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PComponentReference2EditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PComponentReferenceEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PComponentReferenceTargetEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PComponentService2EditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PComponentServiceEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PCompositeEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PConstraintEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PElementMultiplicityEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PElementRolesEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PMultiplicityEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PReferenceEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PReferencePromoteEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PRoleEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PServiceEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PServicePromoteEditPart;
import org.admanager.soapattern.plugin.diagram.edit.parts.PatternEditPart;
import org.admanager.soapattern.plugin.diagram.part.SOADManagementMetamodelDiagramEditorPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class SOADManagementMetamodelElementTypes {

	/**
	 * @generated
	 */
	private SOADManagementMetamodelElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map/*[org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement]*/elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set/*[org.eclipse.gmf.runtime.emf.type.core.IElementType]*/KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType Pattern_1000 = getElementType("org.admanager.soapattern.plugin.diagram.Pattern_1000"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponent_2005 = getElementType("org.admanager.soapattern.plugin.diagram.PComponent_2005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComposite_2006 = getElementType("org.admanager.soapattern.plugin.diagram.PComposite_2006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PMultiplicity_2007 = getElementType("org.admanager.soapattern.plugin.diagram.PMultiplicity_2007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PRole_2008 = getElementType("org.admanager.soapattern.plugin.diagram.PRole_2008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentService_3009 = getElementType("org.admanager.soapattern.plugin.diagram.PComponentService_3009"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentReference_3010 = getElementType("org.admanager.soapattern.plugin.diagram.PComponentReference_3010"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PReference_3011 = getElementType("org.admanager.soapattern.plugin.diagram.PReference_3011"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PService_3012 = getElementType("org.admanager.soapattern.plugin.diagram.PService_3012"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponent_3013 = getElementType("org.admanager.soapattern.plugin.diagram.PComponent_3013"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentService_3014 = getElementType("org.admanager.soapattern.plugin.diagram.PComponentService_3014"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentReference_3015 = getElementType("org.admanager.soapattern.plugin.diagram.PComponentReference_3015"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PConstraint_3016 = getElementType("org.admanager.soapattern.plugin.diagram.PConstraint_3016"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PElementRoles_4006 = getElementType("org.admanager.soapattern.plugin.diagram.PElementRoles_4006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PElementMultiplicity_4007 = getElementType("org.admanager.soapattern.plugin.diagram.PElementMultiplicity_4007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PReferencePromote_4008 = getElementType("org.admanager.soapattern.plugin.diagram.PReferencePromote_4008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PServicePromote_4009 = getElementType("org.admanager.soapattern.plugin.diagram.PServicePromote_4009"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PComponentReferenceTarget_4010 = getElementType("org.admanager.soapattern.plugin.diagram.PComponentReferenceTarget_4010"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return SOADManagementMetamodelDiagramEditorPlugin.getInstance()
						.getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap/*[org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement]*/();

			elements.put(
					Pattern_1000,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPattern());

			elements.put(
					PComponent_2005,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPComponent());

			elements.put(
					PComposite_2006,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPComposite());

			elements.put(
					PMultiplicity_2007,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPMultiplicity());

			elements.put(
					PRole_2008,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPRole());

			elements.put(
					PComponentService_3009,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPComponentService());

			elements.put(
					PComponentReference_3010,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPComponentReference());

			elements.put(
					PReference_3011,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPReference());

			elements.put(
					PService_3012,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPService());

			elements.put(
					PComponent_3013,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPComponent());

			elements.put(
					PComponentService_3014,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPComponentService());

			elements.put(
					PComponentReference_3015,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPComponentReference());

			elements.put(
					PConstraint_3016,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPConstraint());

			elements.put(
					PElementRoles_4006,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPElement_Roles());

			elements.put(
					PElementMultiplicity_4007,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPElement_Multiplicity());

			elements.put(
					PReferencePromote_4008,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPReference_Promote());

			elements.put(
					PServicePromote_4009,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPService_Promote());

			elements.put(
					PComponentReferenceTarget_4010,
					org.admanager.soadmanagement.plugin.soadmanagement.soadmanagementPackage.eINSTANCE
							.getPComponentReference_Target());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet/*[org.eclipse.gmf.runtime.emf.type.core.IElementType]*/();
			KNOWN_ELEMENT_TYPES.add(Pattern_1000);
			KNOWN_ELEMENT_TYPES.add(PComponent_2005);
			KNOWN_ELEMENT_TYPES.add(PComposite_2006);
			KNOWN_ELEMENT_TYPES.add(PMultiplicity_2007);
			KNOWN_ELEMENT_TYPES.add(PRole_2008);
			KNOWN_ELEMENT_TYPES.add(PComponentService_3009);
			KNOWN_ELEMENT_TYPES.add(PComponentReference_3010);
			KNOWN_ELEMENT_TYPES.add(PReference_3011);
			KNOWN_ELEMENT_TYPES.add(PService_3012);
			KNOWN_ELEMENT_TYPES.add(PComponent_3013);
			KNOWN_ELEMENT_TYPES.add(PComponentService_3014);
			KNOWN_ELEMENT_TYPES.add(PComponentReference_3015);
			KNOWN_ELEMENT_TYPES.add(PConstraint_3016);
			KNOWN_ELEMENT_TYPES.add(PElementRoles_4006);
			KNOWN_ELEMENT_TYPES.add(PElementMultiplicity_4007);
			KNOWN_ELEMENT_TYPES.add(PReferencePromote_4008);
			KNOWN_ELEMENT_TYPES.add(PServicePromote_4009);
			KNOWN_ELEMENT_TYPES.add(PComponentReferenceTarget_4010);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

	/**
	 * @generated
	 */
	public static IElementType getElementType(int visualID) {
		switch (visualID) {
		case PatternEditPart.VISUAL_ID:
			return Pattern_1000;
		case PComponentEditPart.VISUAL_ID:
			return PComponent_2005;
		case PCompositeEditPart.VISUAL_ID:
			return PComposite_2006;
		case PMultiplicityEditPart.VISUAL_ID:
			return PMultiplicity_2007;
		case PRoleEditPart.VISUAL_ID:
			return PRole_2008;
		case PComponentServiceEditPart.VISUAL_ID:
			return PComponentService_3009;
		case PComponentReferenceEditPart.VISUAL_ID:
			return PComponentReference_3010;
		case PReferenceEditPart.VISUAL_ID:
			return PReference_3011;
		case PServiceEditPart.VISUAL_ID:
			return PService_3012;
		case PComponent2EditPart.VISUAL_ID:
			return PComponent_3013;
		case PComponentService2EditPart.VISUAL_ID:
			return PComponentService_3014;
		case PComponentReference2EditPart.VISUAL_ID:
			return PComponentReference_3015;
		case PConstraintEditPart.VISUAL_ID:
			return PConstraint_3016;
		case PElementRolesEditPart.VISUAL_ID:
			return PElementRoles_4006;
		case PElementMultiplicityEditPart.VISUAL_ID:
			return PElementMultiplicity_4007;
		case PReferencePromoteEditPart.VISUAL_ID:
			return PReferencePromote_4008;
		case PServicePromoteEditPart.VISUAL_ID:
			return PServicePromote_4009;
		case PComponentReferenceTargetEditPart.VISUAL_ID:
			return PComponentReferenceTarget_4010;
		}
		return null;
	}

}
